/*
 * @Author: Wangjun
 * @Date: 2023-08-14 10:40:47
 * @LastEditTime: 2023-12-10 12:20:44
 * @LastEditors: wangjun haodreams@163.com
 * @Description:内存测点，模拟量输出
 * @FilePath: \xr_node_calc\noderdb\op_la.go
 * hnxr
 */
package noderdb

import (
	"gitee.com/haodreams/op_node/thirdparty"
	"gitee.com/hnxr_1/nodex"
)

func init() {
	nodex.Reister(new(LA))
}

type LA struct {
	nodex.Node
	Y nodex.Double `remark:"输入1"`

	item *thirdparty.Item
	Tag  string
	Kind string //类别

}

func (m *LA) GetModelID() int {
	return nodex.ModOut
}

func (m *LA) Init(mem *nodex.Memory) (err error) {
	outs := make([]*nodex.Out, 1)
	outs[0] = &nodex.Out{Name: "Y", Value: m.Y.DoubleValue}
	m.SetOuts(outs)

	extends := m.GetExtends()
	parent := m.GetParent()
	atag := extends["tag"]
	tag, _ := atag.(string)
	acategory := extends["category"]
	category, _ := acategory.(string)
	if tag != "" {
		m.Tag = tag
		m.Kind = category
		m.item = dataitem.GetMemItem(category, parent.RID, tag)
	}

	return
}

func (m *LA) GetName() string {
	return "LA"
}

/**
 * @description: 节点信息
 * @return {*}
 */
func (m *LA) RegData() []byte {
	return nodex.MakeRegData(m, "内存模拟量输出", m.GetName(), "")
}

func (m *LA) GetParams() []nodex.Valuer {
	return []nodex.Valuer{&m.Y}
}

func (m *LA) Calc() (err error) {
	m.Bad = *m.Y.Bad
	if m.item != nil {
		m.item.V = m.Y.Value
		if m.Bad {
			m.item.Q = 0 //坏点
		} else {
			m.item.Q = 1 //正常测点
		}
	}
	return
}

func (m *LA) GetResult() (v float64, isBad bool) {
	return m.Y.Value, m.Bad
}
